package com.itheima.d4_tcp1;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws Exception {
        //1.创建Socket对象
        Socket socket = new Socket("127.0.0.1", 8050);
        //2.创建缓冲流，把数据写入服务器
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        byte[] bytes1 = "约吗".getBytes();
        bos.write(bytes1);
        bos.flush();
        socket.shutdownOutput();

        //3.接收消息
        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1){
            System.out.println(new String(bytes,0,len));
        }




        socket.close();
    }
}
